package androidx.fragment.app;

import android.app.Activity;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import androidx.lifecycle.e;
import androidx.lifecycle.v;
import b.i.b;

class s {

    /* renamed from: a  reason: collision with root package name */
    private final l f657a;

    /* renamed from: b  reason: collision with root package name */
    private final Fragment f658b;

    /* renamed from: c  reason: collision with root package name */
    private int f659c = -1;

    static /* synthetic */ class a {

        /* renamed from: a  reason: collision with root package name */
        static final /* synthetic */ int[] f660a;

        /* JADX WARNING: Can't wrap try/catch for region: R(6:0|1|2|3|4|(3:5|6|8)) */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Missing exception handler attribute for start block: B:3:0x0012 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:5:0x001d */
        static {
            /*
                androidx.lifecycle.e$b[] r0 = androidx.lifecycle.e.b.values()
                int r0 = r0.length
                int[] r0 = new int[r0]
                f660a = r0
                androidx.lifecycle.e$b r1 = androidx.lifecycle.e.b.RESUMED     // Catch:{ NoSuchFieldError -> 0x0012 }
                int r1 = r1.ordinal()     // Catch:{ NoSuchFieldError -> 0x0012 }
                r2 = 1
                r0[r1] = r2     // Catch:{ NoSuchFieldError -> 0x0012 }
            L_0x0012:
                int[] r0 = f660a     // Catch:{ NoSuchFieldError -> 0x001d }
                androidx.lifecycle.e$b r1 = androidx.lifecycle.e.b.STARTED     // Catch:{ NoSuchFieldError -> 0x001d }
                int r1 = r1.ordinal()     // Catch:{ NoSuchFieldError -> 0x001d }
                r2 = 2
                r0[r1] = r2     // Catch:{ NoSuchFieldError -> 0x001d }
            L_0x001d:
                int[] r0 = f660a     // Catch:{ NoSuchFieldError -> 0x0028 }
                androidx.lifecycle.e$b r1 = androidx.lifecycle.e.b.CREATED     // Catch:{ NoSuchFieldError -> 0x0028 }
                int r1 = r1.ordinal()     // Catch:{ NoSuchFieldError -> 0x0028 }
                r2 = 3
                r0[r1] = r2     // Catch:{ NoSuchFieldError -> 0x0028 }
            L_0x0028:
                return
            */
            throw new UnsupportedOperationException("Method not decompiled: androidx.fragment.app.s.a.<clinit>():void");
        }
    }

    s(l lVar, Fragment fragment) {
        this.f657a = lVar;
        this.f658b = fragment;
    }

    s(l lVar, Fragment fragment, r rVar) {
        this.f657a = lVar;
        this.f658b = fragment;
        fragment.mSavedViewState = null;
        fragment.mBackStackNesting = 0;
        fragment.mInLayout = false;
        fragment.mAdded = false;
        Fragment fragment2 = fragment.mTarget;
        fragment.mTargetWho = fragment2 != null ? fragment2.mWho : null;
        Fragment fragment3 = this.f658b;
        fragment3.mTarget = null;
        Bundle bundle = rVar.n;
        fragment3.mSavedFragmentState = bundle == null ? new Bundle() : bundle;
    }

    s(l lVar, ClassLoader classLoader, i iVar, r rVar) {
        this.f657a = lVar;
        this.f658b = iVar.a(classLoader, rVar.f654b);
        Bundle bundle = rVar.k;
        if (bundle != null) {
            bundle.setClassLoader(classLoader);
        }
        this.f658b.setArguments(rVar.k);
        Fragment fragment = this.f658b;
        fragment.mWho = rVar.f655c;
        fragment.mFromLayout = rVar.f656d;
        fragment.mRestored = true;
        fragment.mFragmentId = rVar.e;
        fragment.mContainerId = rVar.f;
        fragment.mTag = rVar.g;
        fragment.mRetainInstance = rVar.h;
        fragment.mRemoving = rVar.i;
        fragment.mDetached = rVar.j;
        fragment.mHidden = rVar.l;
        fragment.mMaxState = e.b.values()[rVar.m];
        Bundle bundle2 = rVar.n;
        if (bundle2 != null) {
            this.f658b.mSavedFragmentState = bundle2;
        } else {
            this.f658b.mSavedFragmentState = new Bundle();
        }
        if (m.p0(2)) {
            "Instantiated fragment " + this.f658b;
        }
    }

    private Bundle n() {
        Bundle bundle = new Bundle();
        this.f658b.performSaveInstanceState(bundle);
        this.f657a.j(this.f658b, bundle, false);
        if (bundle.isEmpty()) {
            bundle = null;
        }
        if (this.f658b.mView != null) {
            p();
        }
        if (this.f658b.mSavedViewState != null) {
            if (bundle == null) {
                bundle = new Bundle();
            }
            bundle.putSparseParcelableArray("android:view_state", this.f658b.mSavedViewState);
        }
        if (!this.f658b.mUserVisibleHint) {
            if (bundle == null) {
                bundle = new Bundle();
            }
            bundle.putBoolean("android:user_visible_hint", this.f658b.mUserVisibleHint);
        }
        return bundle;
    }

    /* access modifiers changed from: package-private */
    public void a() {
        if (m.p0(3)) {
            "moveto ACTIVITY_CREATED: " + this.f658b;
        }
        Fragment fragment = this.f658b;
        fragment.performActivityCreated(fragment.mSavedFragmentState);
        l lVar = this.f657a;
        Fragment fragment2 = this.f658b;
        lVar.a(fragment2, fragment2.mSavedFragmentState, false);
    }

    /* access modifiers changed from: package-private */
    public void b(j<?> jVar, m mVar, Fragment fragment) {
        Fragment fragment2 = this.f658b;
        fragment2.mHost = jVar;
        fragment2.mParentFragment = fragment;
        fragment2.mFragmentManager = mVar;
        this.f657a.g(fragment2, jVar.f(), false);
        this.f658b.performAttach();
        Fragment fragment3 = this.f658b;
        Fragment fragment4 = fragment3.mParentFragment;
        if (fragment4 == null) {
            jVar.h(fragment3);
        } else {
            fragment4.onAttachFragment(fragment3);
        }
        this.f657a.b(this.f658b, jVar.f(), false);
    }

    /* access modifiers changed from: package-private */
    public int c() {
        int i = this.f659c;
        Fragment fragment = this.f658b;
        if (fragment.mFromLayout) {
            i = fragment.mInLayout ? Math.max(i, 1) : i < 2 ? Math.min(i, fragment.mState) : Math.min(i, 1);
        }
        if (!this.f658b.mAdded) {
            i = Math.min(i, 1);
        }
        Fragment fragment2 = this.f658b;
        if (fragment2.mRemoving) {
            i = fragment2.isInBackStack() ? Math.min(i, 1) : Math.min(i, -1);
        }
        Fragment fragment3 = this.f658b;
        if (fragment3.mDeferStart && fragment3.mState < 3) {
            i = Math.min(i, 2);
        }
        int i2 = a.f660a[this.f658b.mMaxState.ordinal()];
        return i2 != 1 ? i2 != 2 ? i2 != 3 ? Math.min(i, -1) : Math.min(i, 1) : Math.min(i, 3) : i;
    }

    /* access modifiers changed from: package-private */
    public void d() {
        if (m.p0(3)) {
            "moveto CREATED: " + this.f658b;
        }
        Fragment fragment = this.f658b;
        if (!fragment.mIsCreated) {
            this.f657a.h(fragment, fragment.mSavedFragmentState, false);
            Fragment fragment2 = this.f658b;
            fragment2.performCreate(fragment2.mSavedFragmentState);
            l lVar = this.f657a;
            Fragment fragment3 = this.f658b;
            lVar.c(fragment3, fragment3.mSavedFragmentState, false);
            return;
        }
        fragment.restoreChildFragmentState(fragment.mSavedFragmentState);
        this.f658b.mState = 1;
    }

    /* JADX WARNING: type inference failed for: r5v15, types: [android.view.View] */
    /* access modifiers changed from: package-private */
    /* JADX WARNING: Multi-variable type inference failed */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void e(androidx.fragment.app.f r5) {
        /*
            r4 = this;
            androidx.fragment.app.Fragment r0 = r4.f658b
            boolean r0 = r0.mFromLayout
            if (r0 == 0) goto L_0x0007
            return
        L_0x0007:
            r0 = 3
            boolean r0 = androidx.fragment.app.m.p0(r0)
            if (r0 == 0) goto L_0x0020
            java.lang.StringBuilder r0 = new java.lang.StringBuilder
            r0.<init>()
            java.lang.String r1 = "moveto CREATE_VIEW: "
            r0.append(r1)
            androidx.fragment.app.Fragment r1 = r4.f658b
            r0.append(r1)
            r0.toString()
        L_0x0020:
            r0 = 0
            androidx.fragment.app.Fragment r1 = r4.f658b
            android.view.ViewGroup r2 = r1.mContainer
            if (r2 == 0) goto L_0x002a
            r0 = r2
            goto L_0x009f
        L_0x002a:
            int r1 = r1.mContainerId
            if (r1 == 0) goto L_0x009f
            r0 = -1
            if (r1 == r0) goto L_0x0081
            android.view.View r5 = r5.c(r1)
            r0 = r5
            android.view.ViewGroup r0 = (android.view.ViewGroup) r0
            if (r0 != 0) goto L_0x009f
            androidx.fragment.app.Fragment r5 = r4.f658b
            boolean r1 = r5.mRestored
            if (r1 == 0) goto L_0x0041
            goto L_0x009f
        L_0x0041:
            android.content.res.Resources r5 = r5.getResources()     // Catch:{ NotFoundException -> 0x004e }
            androidx.fragment.app.Fragment r0 = r4.f658b     // Catch:{ NotFoundException -> 0x004e }
            int r0 = r0.mContainerId     // Catch:{ NotFoundException -> 0x004e }
            java.lang.String r5 = r5.getResourceName(r0)     // Catch:{ NotFoundException -> 0x004e }
            goto L_0x0050
        L_0x004e:
            java.lang.String r5 = "unknown"
        L_0x0050:
            java.lang.IllegalArgumentException r0 = new java.lang.IllegalArgumentException
            java.lang.StringBuilder r1 = new java.lang.StringBuilder
            r1.<init>()
            java.lang.String r2 = "No view found for id 0x"
            r1.append(r2)
            androidx.fragment.app.Fragment r2 = r4.f658b
            int r2 = r2.mContainerId
            java.lang.String r2 = java.lang.Integer.toHexString(r2)
            r1.append(r2)
            java.lang.String r2 = " ("
            r1.append(r2)
            r1.append(r5)
            java.lang.String r5 = ") for fragment "
            r1.append(r5)
            androidx.fragment.app.Fragment r5 = r4.f658b
            r1.append(r5)
            java.lang.String r5 = r1.toString()
            r0.<init>(r5)
            throw r0
        L_0x0081:
            java.lang.IllegalArgumentException r5 = new java.lang.IllegalArgumentException
            java.lang.StringBuilder r0 = new java.lang.StringBuilder
            r0.<init>()
            java.lang.String r1 = "Cannot create fragment "
            r0.append(r1)
            androidx.fragment.app.Fragment r1 = r4.f658b
            r0.append(r1)
            java.lang.String r1 = " for a container view with no id"
            r0.append(r1)
            java.lang.String r0 = r0.toString()
            r5.<init>(r0)
            throw r5
        L_0x009f:
            androidx.fragment.app.Fragment r5 = r4.f658b
            r5.mContainer = r0
            android.os.Bundle r1 = r5.mSavedFragmentState
            android.view.LayoutInflater r1 = r5.performGetLayoutInflater(r1)
            androidx.fragment.app.Fragment r2 = r4.f658b
            android.os.Bundle r2 = r2.mSavedFragmentState
            r5.performCreateView(r1, r0, r2)
            androidx.fragment.app.Fragment r5 = r4.f658b
            android.view.View r5 = r5.mView
            if (r5 == 0) goto L_0x0107
            r1 = 0
            r5.setSaveFromParentEnabled(r1)
            androidx.fragment.app.Fragment r5 = r4.f658b
            android.view.View r2 = r5.mView
            int r3 = b.i.b.fragment_container_view_tag
            r2.setTag(r3, r5)
            if (r0 == 0) goto L_0x00cc
            androidx.fragment.app.Fragment r5 = r4.f658b
            android.view.View r5 = r5.mView
            r0.addView(r5)
        L_0x00cc:
            androidx.fragment.app.Fragment r5 = r4.f658b
            boolean r0 = r5.mHidden
            if (r0 == 0) goto L_0x00d9
            android.view.View r5 = r5.mView
            r0 = 8
            r5.setVisibility(r0)
        L_0x00d9:
            androidx.fragment.app.Fragment r5 = r4.f658b
            android.view.View r5 = r5.mView
            b.f.l.s.c0(r5)
            androidx.fragment.app.Fragment r5 = r4.f658b
            android.view.View r0 = r5.mView
            android.os.Bundle r2 = r5.mSavedFragmentState
            r5.onViewCreated(r0, r2)
            androidx.fragment.app.l r5 = r4.f657a
            androidx.fragment.app.Fragment r0 = r4.f658b
            android.view.View r2 = r0.mView
            android.os.Bundle r3 = r0.mSavedFragmentState
            r5.m(r0, r2, r3, r1)
            androidx.fragment.app.Fragment r5 = r4.f658b
            android.view.View r0 = r5.mView
            int r0 = r0.getVisibility()
            if (r0 != 0) goto L_0x0105
            androidx.fragment.app.Fragment r0 = r4.f658b
            android.view.ViewGroup r0 = r0.mContainer
            if (r0 == 0) goto L_0x0105
            r1 = 1
        L_0x0105:
            r5.mIsNewlyAdded = r1
        L_0x0107:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.fragment.app.s.e(androidx.fragment.app.f):void");
    }

    /* access modifiers changed from: package-private */
    public void f(j<?> jVar, p pVar) {
        if (m.p0(3)) {
            "movefrom CREATED: " + this.f658b;
        }
        Fragment fragment = this.f658b;
        boolean z = true;
        boolean z2 = fragment.mRemoving && !fragment.isInBackStack();
        if (z2 || pVar.o(this.f658b)) {
            if (jVar instanceof v) {
                z = pVar.m();
            } else if (jVar.f() instanceof Activity) {
                z = true ^ ((Activity) jVar.f()).isChangingConfigurations();
            }
            if (z2 || z) {
                pVar.g(this.f658b);
            }
            this.f658b.performDestroy();
            this.f657a.d(this.f658b, false);
            return;
        }
        this.f658b.mState = 0;
    }

    /* access modifiers changed from: package-private */
    public void g(p pVar) {
        if (m.p0(3)) {
            "movefrom ATTACHED: " + this.f658b;
        }
        this.f658b.performDetach();
        boolean z = false;
        this.f657a.e(this.f658b, false);
        Fragment fragment = this.f658b;
        fragment.mState = -1;
        fragment.mHost = null;
        fragment.mParentFragment = null;
        fragment.mFragmentManager = null;
        if (fragment.mRemoving && !fragment.isInBackStack()) {
            z = true;
        }
        if (z || pVar.o(this.f658b)) {
            if (m.p0(3)) {
                "initState called for fragment: " + this.f658b;
            }
            this.f658b.initState();
        }
    }

    /* access modifiers changed from: package-private */
    public void h() {
        Fragment fragment = this.f658b;
        if (fragment.mFromLayout && fragment.mInLayout && !fragment.mPerformedCreateView) {
            if (m.p0(3)) {
                "moveto CREATE_VIEW: " + this.f658b;
            }
            Fragment fragment2 = this.f658b;
            fragment2.performCreateView(fragment2.performGetLayoutInflater(fragment2.mSavedFragmentState), (ViewGroup) null, this.f658b.mSavedFragmentState);
            View view = this.f658b.mView;
            if (view != null) {
                view.setSaveFromParentEnabled(false);
                Fragment fragment3 = this.f658b;
                fragment3.mView.setTag(b.fragment_container_view_tag, fragment3);
                Fragment fragment4 = this.f658b;
                if (fragment4.mHidden) {
                    fragment4.mView.setVisibility(8);
                }
                Fragment fragment5 = this.f658b;
                fragment5.onViewCreated(fragment5.mView, fragment5.mSavedFragmentState);
                l lVar = this.f657a;
                Fragment fragment6 = this.f658b;
                lVar.m(fragment6, fragment6.mView, fragment6.mSavedFragmentState, false);
            }
        }
    }

    /* access modifiers changed from: package-private */
    public Fragment i() {
        return this.f658b;
    }

    /* access modifiers changed from: package-private */
    public void j() {
        if (m.p0(3)) {
            "movefrom RESUMED: " + this.f658b;
        }
        this.f658b.performPause();
        this.f657a.f(this.f658b, false);
    }

    /* access modifiers changed from: package-private */
    public void k(ClassLoader classLoader) {
        Bundle bundle = this.f658b.mSavedFragmentState;
        if (bundle != null) {
            bundle.setClassLoader(classLoader);
            Fragment fragment = this.f658b;
            fragment.mSavedViewState = fragment.mSavedFragmentState.getSparseParcelableArray("android:view_state");
            Fragment fragment2 = this.f658b;
            fragment2.mTargetWho = fragment2.mSavedFragmentState.getString("android:target_state");
            Fragment fragment3 = this.f658b;
            if (fragment3.mTargetWho != null) {
                fragment3.mTargetRequestCode = fragment3.mSavedFragmentState.getInt("android:target_req_state", 0);
            }
            Fragment fragment4 = this.f658b;
            Boolean bool = fragment4.mSavedUserVisibleHint;
            if (bool != null) {
                fragment4.mUserVisibleHint = bool.booleanValue();
                this.f658b.mSavedUserVisibleHint = null;
            } else {
                fragment4.mUserVisibleHint = fragment4.mSavedFragmentState.getBoolean("android:user_visible_hint", true);
            }
            Fragment fragment5 = this.f658b;
            if (!fragment5.mUserVisibleHint) {
                fragment5.mDeferStart = true;
            }
        }
    }

    /* access modifiers changed from: package-private */
    public void l() {
        if (m.p0(3)) {
            "moveto RESTORE_VIEW_STATE: " + this.f658b;
        }
        Fragment fragment = this.f658b;
        if (fragment.mView != null) {
            fragment.restoreViewState(fragment.mSavedFragmentState);
        }
        this.f658b.mSavedFragmentState = null;
    }

    /* access modifiers changed from: package-private */
    public void m() {
        if (m.p0(3)) {
            "moveto RESUMED: " + this.f658b;
        }
        this.f658b.performResume();
        this.f657a.i(this.f658b, false);
        Fragment fragment = this.f658b;
        fragment.mSavedFragmentState = null;
        fragment.mSavedViewState = null;
    }

    /* access modifiers changed from: package-private */
    public r o() {
        r rVar = new r(this.f658b);
        if (this.f658b.mState <= -1 || rVar.n != null) {
            rVar.n = this.f658b.mSavedFragmentState;
        } else {
            Bundle n = n();
            rVar.n = n;
            if (this.f658b.mTargetWho != null) {
                if (n == null) {
                    rVar.n = new Bundle();
                }
                rVar.n.putString("android:target_state", this.f658b.mTargetWho);
                int i = this.f658b.mTargetRequestCode;
                if (i != 0) {
                    rVar.n.putInt("android:target_req_state", i);
                }
            }
        }
        return rVar;
    }

    /* access modifiers changed from: package-private */
    public void p() {
        if (this.f658b.mView != null) {
            SparseArray<Parcelable> sparseArray = new SparseArray<>();
            this.f658b.mView.saveHierarchyState(sparseArray);
            if (sparseArray.size() > 0) {
                this.f658b.mSavedViewState = sparseArray;
            }
        }
    }

    /* access modifiers changed from: package-private */
    public void q(int i) {
        this.f659c = i;
    }

    /* access modifiers changed from: package-private */
    public void r() {
        if (m.p0(3)) {
            "moveto STARTED: " + this.f658b;
        }
        this.f658b.performStart();
        this.f657a.k(this.f658b, false);
    }

    /* access modifiers changed from: package-private */
    public void s() {
        if (m.p0(3)) {
            "movefrom STARTED: " + this.f658b;
        }
        this.f658b.performStop();
        this.f657a.l(this.f658b, false);
    }
}
